<?php


namespace App\Http\Controllers\CmsApi;

use App\Http\Controllers\BaseController;
use App\Http\Model\Hint;
use App\Http\Services\TogetherGameService;
use App\Lib\Response;
use Illuminate\Http\Request;

class InnerTogetherGameController extends BaseController
{
    protected $togetherGameService;

    public function __construct()
    {
        $this->togetherGameService = new TogetherGameService();
    }

    //一起玩添加/修改
    public function dataInsert(Request $request){
        $id = $request->post('id',0);//数据id
        $gameName = $request->post('game_name','');//游戏名称
        $diamond_value = $request->post('diamond_value',0);//钻石限制
        $jump_url = $request->post('jump_url','');//跳转地址
        $video_url = $request->post('video_url','');//视频链接
        $scale = $request->post('scale','');//视频比例值
        $default_url = $request->post('default_url','');//默认图
        $icon_url = $request->post('icon_url','');//icon缩略
        $sort = $request->post('sort',0);//排序
        $status = $request->post('status',2);//显示状态1=开启 2=关闭
        if(empty($gameName)){
            Response::returnResult(Hint::PARAM_ERROR);
        }
        if(empty($diamond_value)){
            Response::returnResult(Hint::PARAM_ERROR);
        }
        if(empty($jump_url)){
            Response::returnResult(Hint::PARAM_ERROR);
        }
        if(empty($video_url)){
            Response::returnResult(Hint::PARAM_ERROR);
        }
        $status = $this->togetherGameService->dataChange($id, $gameName, $diamond_value, $jump_url, $video_url, $scale, $sort, $status, $default_url, $icon_url);
        if(!$status){
            Response::returnResult(Hint::ERR_NORMAL,[],'失败');
        }
        Response::returnResult(Hint::SUCCESS);
    }

    //删除数据
    public function deleteGame(Request $request){
        $id = $request->post('id',0);
        if(empty($id)){
            Response::returnResult(Hint::ERROR);
        }
        $status = $this->togetherGameService->deleteGame($id);
        if(!$status){
            Response::returnResult(Hint::ERR_NORMAL,[],'失败');
        }
        Response::returnResult(Hint::SUCCESS);
    }

    //一起玩总开关设置
    public function setGameOpen(Request $request){
        $status = $request->post('status',2);//状态 1=开启 2=关闭
        $diamond = $request->post('diamond',0);//钻石
        $status = $this->togetherGameService->setGameOpen($status,$diamond);
        if(!$status){
            Response::returnResult(Hint::ERR_NORMAL,[],'失败');
        }
        Response::returnResult(Hint::SUCCESS);
    }

    //一起玩签到配置
    public function setDaySign(Request $request){
        $id = $request->post('id',0);
        $signday = $request->post('sigin_day',1);//签到天
        $img = $request->post('pic','');//签到图片
        $sendType = $request->post('send_type',1);//奖励类型1=娱乐积分 2=金豆 3=头像框/座驾/进场特效
        $sendId = $request->post('send_id',0);//奖励id type=3必传
        $sendNum = $request->post('send_num',1);//奖励数量
        $status = $request->post('status',2);//显示状态1=显示 2=不显示
        if(empty($sendType)){
            Response::returnResult(Hint::PARAM_ERROR, [],'奖励类型必填');
        }
        if(empty($img)){
            Response::returnResult(Hint::PARAM_ERROR, [],'签到图片必填');
        }
        if(empty($signday)){
            Response::returnResult(Hint::PARAM_ERROR, [],'签到天数必填');
        }
        if($sendType == 3 && empty($sendId)){
            Response::returnResult(Hint::PARAM_ERROR, [],'奖励id必填');
        }
        $status = $this->togetherGameService->setDaySign($id, $signday, $img, $sendType, $sendId, $sendNum, $status);
        if(!$status){
            Response::returnResult(Hint::ERR_NORMAL,[],'失败');
        }
        Response::returnResult(Hint::SUCCESS);
    }
}